#!/bin/sh
#
# Plugin to monitor heating sensors.
#
# Usage: Place in /etc/munin/node.d/ (or link it there  using ln -s)
#
# Parameters understood:
#
# 	config   (required)
# 	autoconf (optional - used by munin-config)
#
# Magic markers - optional - used by installation scripts and
# munin-config:
#
#%# family=auto
#%# capabilities=autoconf

#read owfs config, then export it so backticks work
. /etc/default/owfs
export CLIENT_OPTS

if [ "$1" = "autoconf" ]; then
	if owdir $CLIENT_OPTS ; then
		echo yes
		exit 0
	else
		echo no
		exit 1
	fi
fi


if [ "$1" = "config" ]; then

	MAX="126"
	MIN="-2"
#	if [ "$scaleto100" = "yes" ]; then
#		graphlimit=100
#	else
#		graphlimit=$PERCENT
#	fi
	WARNING="80"
	CRITICAL="95"
	echo 'graph_title Tank Temperatures'
	echo "graph_order tank5 tank4 tank3 tank2 tank1"
#	echo "graph_args --base 1000 -r --lower-limit 0 --upper-limit $graphlimit"
	echo 'graph_vlabel Degrees Celcius'
#	echo 'graph_scale no'
	echo 'graph_info This graph shows hot water tank temperatures.'
	echo 'graph_category solar'
	echo 'graph_period minute'
	echo 'tank1.label tank-base'
	echo 'tank1.draw LINE2'
	echo "tank1.max $MAX"
	echo "tank1.min $MIN"
	echo 'tank1.type GAUGE'
	echo "tank1.warning $WARNING" 
	echo "tank1.critical $CRITICAL" 
	echo "tank1.info Temp at base of tank"
	echo 'tank2.label tank2'
	echo 'tank2.draw LINE1'
	echo "tank2.min $MIN"
	echo "tank2.max $MAX"
	echo "tank2.warning $WARNING"
	echo "tank2.critical $WARNING"
	echo 'tank2.type GAUGE'
	echo 'tank2.info Temp 20cm up tank'
	echo 'tank3.label tank3'
	echo 'tank3.draw LINE1'
	echo "tank3.min $MIN"
	echo "tank3.max $MAX"
	echo "tank3.warning $WARNING"
	echo "tank3.critical $WARNING"
	echo 'tank3.type GAUGE'
	echo 'tank3.info Temp 40cm up tank'
	echo 'tank4.label tank4'
	echo 'tank4.draw LINE1'
	echo "tank4.min $MIN"
	echo "tank4.max $MAX"
	echo "tank4.warning $WARNING"
	echo "tank4.critical $WARNING"
	echo 'tank4.type GAUGE'
	echo 'tank4.info Temp 60cm up tank'
	echo 'tank5.label tank-top'
	echo 'tank5.draw LINE2'
	echo "tank5.min $MIN"
	echo "tank5.max $MAX"
	echo "tank5.warning $WARNING"
	echo "tank5.critical $WARNING"
	echo 'tank5.type GAUGE'
	echo 'tank5.info Temp at top of tank'

#if [ "$scaleto100" = "yes" ]; then
#	echo "system.cdef system,$NCPU,/"
#	echo "user.cdef user,$NCPU,/"
#	echo "nice.cdef nice,$NCPU,/"
#	echo "idle.cdef idle,$NCPU,/"
#fi
	exit 0
fi


TANK1SENSOR="28.850874010000"
TANK2SENSOR="10.AD188A010800"
TANK3SENSOR="10.634B8A010800"
TANK4SENSOR="10.E7EE89010800"
TANK5SENSOR="10.AEEA89010800"

TANK1=`owread $CLIENT_OPTS $TANK1SENSOR/temperature`
TANK2=`owread $CLIENT_OPTS $TANK2SENSOR/temperature`
TANK3=`owread $CLIENT_OPTS $TANK3SENSOR/temperature`
TANK4=`owread $CLIENT_OPTS $TANK4SENSOR/temperature`
TANK5=`owread $CLIENT_OPTS $TANK5SENSOR/temperature`

#	awk '/^cpu / { print "user.value " $2 "\nnice.value " $3 "\nsystem.value " $4 "\nidle.value " $5 }' < /proc/stat
	echo "tank1.value $TANK1"
	echo "tank2.value $TANK2"
	echo "tank3.value $TANK3"
	echo "tank4.value $TANK4"
	echo "tank5.value $TANK5"

